class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums) {
        int size = nums.size(), prev = 1;
        vector<int> ans(size, 1);
        for(int i = size - 2; i >= 0; --i)
            ans[i] = ans[i + 1] * nums[i + 1];
        for(int i = 0; i < size; ++i)
        {
            if(i) prev *= nums[i - 1];
            ans[i] *= prev;
        }
        return ans;
    }
};